﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Chinesys.Domain.InputValidations;


namespace Chinesys.UI.Controls
{
    public partial class ValidationSummary : System.Web.UI.UserControl
    {
        private List<InputValidationError> errors;

        public List<InputValidationError> Errors
        {
            get { return errors; }
            set
            {
                errors = value;

                if (errors.Any())
                {
                    btnShowValidationErrors.Visible = true;

                    ListItem item;
                    lstValidations.Items.Clear();
                    foreach (InputValidationError err in Errors)
                    {
                        item = new ListItem(err.ErrorMessage);
                        lstValidations.Items.Add(item);
                    }

                }
                else
                {
                    btnShowValidationErrors.Visible = false;
                    lstValidations.Visible = false;
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void Clear()
        {
            Errors = new List<InputValidationError>();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.errors = new List<InputValidationError>();
        }

        //TODO: verificar porq aveces al hacer click en el boton este desaparece.
        protected void btnShowValidationErrors_Click(object sender, EventArgs e)
        {
            if (lstValidations.Visible)
                lstValidations.Visible = false;
            else
                lstValidations.Visible = true;
        }
    }
}